using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using System;
using System.Collections.Generic;
using System.Text;

namespace EntLibContrib.Logging.Install
{
    internal class LoggingConfigurationLoader : MarshalByRefObject
    {
        private List<EventLogConfiguration> eventLogs_;

        public LoggingConfigurationLoader()
        {
            this.eventLogs_ = new List<EventLogConfiguration>();

            IConfigurationSource configSource =
                ConfigurationSourceFactory.Create();
            LoggingSettings loggingConfig =
                (LoggingSettings)configSource.GetSection(
                LoggingSettings.SectionName);
            foreach (TraceListenerData tld in loggingConfig.TraceListeners)
            {
                FormattedEventLogTraceListenerData feltld =
                    tld as FormattedEventLogTraceListenerData;
                if (feltld != null)
                {
                    EventLogConfiguration elc =
                        new EventLogConfiguration(feltld.Log, feltld.Source);
                    this.eventLogs_.Add(elc);
                }
            }
        }

        internal IList<EventLogConfiguration> EventLogs
        {
            get { return this.eventLogs_; }
        }
    }
}
